package cn.framelife.rainbow.db.oracle;

import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.List;

import cn.framelife.rainbow.db.BaseTable;
import cn.framelife.rainbow.db.DatabaseMessage;
import cn.framelife.rainbow.db.creator.part.EntityCreator;
import cn.framelife.rainbow.db.entity.ClazzProperty;
import cn.framelife.rainbow.util.DatabaseCache;

/**
 * Oracle 生成实体类对象
 * 
 * @author 潘广伟
 *
 */
public class OracleEntityCreator extends EntityCreator {
	public OracleEntityCreator(DatabaseMessage databaseMessage) {
		super.databaseMessage = databaseMessage;
	}
	
	public List<ClazzProperty> createEntities(List<String> tableNames,String modulePackage) throws Exception {
		DatabaseMetaData metaData = DatabaseCache.getConnection().getMetaData();
		
		List<ClazzProperty> entities = new ArrayList<ClazzProperty>();
		
		for (String tableName : tableNames) {
			BaseTable table = new OracleTable(tableName, metaData);
			ClazzProperty entity = createEntity(table,modulePackage);
			entities.add(entity);
		}
		return entities;
	}
	
	public ClazzProperty getEntity(String tableName,String modulePackage) throws Exception {
		BaseTable table = new OracleTable(tableName, DatabaseCache.getConnection().getMetaData());
		return  createEntity(table,modulePackage);
	}
}
